package com.jz.community.moduleshoppingguide.neighbor.task;

import android.app.Activity;

import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.moduleshoppingguide.neighbor.bean.CircleNoticeBean;

import java.util.HashMap;

public class CircleNoticeTask extends RxTask<String, Integer, CircleNoticeBean> {


    private Activity activity;
    private ITaskCallbackListener taskListener;

    public CircleNoticeTask(Activity activity,
                            ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected CircleNoticeBean doInBackground(String... strings) {
        String result = OkHttpUtil.get(Constant.NEIGH_HEADLINE + "/" + strings[0], new HashMap<>());
        CircleNoticeBean circleNoticeBean = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            circleNoticeBean = JsonUtils.parseObject(result, CircleNoticeBean.class);
        }
        return circleNoticeBean;
    }

    @Override
    protected void onPostExecute(CircleNoticeBean result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

}
